import 'package:flutter_baselib_example/module/login/model/login_result_bean.dart';
import 'package:flutter_baselib_example/module/userlist/model/user_detail_bean.dart';

///@date:  2021/2/26 14:02
///@author:  lixu
///@description: http json解析bean
///TODO 所有需要解析的对象都要在下面注册，否则无法解析json为object
class BeanFactory {
  ///json解析
  ///[jsonData] json map
  static T parseObject<T>(Map<String, dynamic> jsonData) {
    if (jsonData == null) {
      return null;
    } else if (T.toString() == "LoginResultBean") {
      return LoginResultBean.fromJsonMap(jsonData) as T;
    } else if (T.toString() == "UserDetailBean") {
      return UserDetailBean.fromJsonMap(jsonData) as T;
    } else {
      return jsonData as T;
    }
  }
}
